<?php
/**
 * Created by PhpStorm.
 * User: cd
 * Date: 2017/8/30
 * Time: 20:12
 */

namespace Home\Controller;


use Think\Controller;

class CommoController extends Controller
{
    const RET_SUCCESS = 0;
    const RET_FAILED = 1;

    /**
     * ajax返回
     * @param int $code 错误码
     * @param string $msg 错误信息
     * @param array $data
     * @param int $count
     */
    public function ajaxRet($code = self::RET_SUCCESS, $msg = "SUCCESS", $data = [], $count = 0)
    {
        $ret = ['code' => $code, 'msg' => $msg, 'data' => $data, 'count' => $count];

        $this->ajaxReturn($ret);
    }
     public function __construct()
     {
         parent::__construct();
         if (!$this->isLogin()){
             $this->error('您还没有登录哦！',U('Login/login'));
         }

//         $get = I('get.id');
//         session('id',$get);
//
//         $vo = D('sort');
//         $res = $vo->select();
//         $this->assign('res',$res);
     }
    public function isLogin()
    {
        //判断login页面不用验证
        if (CONTROLLER_NAME == "Login") {
            return true;
        }
        //判断已经登录的页面不用验证
        if (session('member')) {
            return true;
        }

        return false;
    }
}